home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
SETUP
/
US
/
CBUILDER
/
DATA.Z
/
FOOTMAIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-13
|
13KB
|
450 lines
//----------------------------------------------------------------------------
//Borland C++Builder
//Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <vcl/mmsystem.hpp>
#include "footmain.h"
#include "instr.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
char numbuf[10];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MoveForward(TObject *Sender)
{
if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
return;
if (!running)
TogglePlay(true);
if (Runningback->Left < TACKLEROW3 - 2)
{
if (field[rbx+1][rby].player != NULL)
{
Sacked(field[rbx+1][rby].player);
return;
}
field[rbx][rby].player = NULL;
field[rbx][rby].rb = false;
Runningback->Left += 22;
rbx++;
}
else
{
if (field[0][rby].player != NULL)
{
Sacked(field[0][rby].player);
return;
}
field[rbx][rby].player = NULL;
field[rbx][rby].rb = false;
Runningback->Left = RBLEFT;
rbx = 0;
}
YardsToGo--;
FieldPosition++;
if (FieldPosition == 100)
{
sndPlaySound("td.wav", SND_SYNC);
running = false;
ShowField(false);
Home+=7;
HomeDisplay->Caption = itoa(Home, numbuf, 10);
FieldPosition=80; // Starting position for visitor
Down = 1;
YardsToGo = 10;
Computer->Visible = true;
return;
}
field[rbx][rby].player = Runningback;
field[rbx][rby].rb = true;
}
//---------------------------------------------------------------------
void __fastcall TForm1::MoveUp(TObject *Sender)
{
if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
return;
if (!running)
TogglePlay(true);
if (Runningback->Top == RBTOP)
return; // already as up as it gets
if (field[rbx][rby-1].player != NULL)
{
Sacked(field[rbx][rby-1].player);
return;
}
if (Runningback->Top == RBBOTTOM)
Runningback->Top = RBMIDDLE;
else if (Runningback->Top == RBMIDDLE)
Runningback->Top = RBTOP;
field[rbx][rby].player = NULL;
field[rbx][rby].rb = false;
rby--;
field[rbx][rby].player = Runningback;
field[rbx][rby].rb = true;
}
//---------------------------------------------------------------------
void __fastcall TForm1::MoveDown(TObject *Sender)
{
if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
return;
if (!running)
TogglePlay(true);
if (Runningback->Top == RBBOTTOM)
return; // already as down as it gets
if (field[rbx][rby+1].player != NULL)
{
Sacked(field[rbx][rby+1].player);
return;
}
if (Runningback->Top == RBTOP)
Runningback->Top = RBMIDDLE;
else if (Runningback->Top == RBMIDDLE)
Runningback->Top = RBBOTTOM;
field[rbx][rby].player = NULL;
field[rbx][rby].rb = false;
rby++;
field[rbx][rby].player = Runningback;
field[rbx][rby].rb = true;
}
//---------------------------------------------------------------------
void __fastcall TForm1::Switched(TObject *Sender)
{
switch (OnOffSwitch->Position)
{
case 1: {
Timer->Interval = 250;
HomeDisplay->Visible = true;
VisitorDisplay->Visible = true;
TimeDisplay->Visible = true;
ResetGame(NULL);
break;
}
case 2: {
ShowField(false);
HomeDisplay->Visible = false;
VisitorDisplay->Visible = false;
TimeDisplay->Visible = false;
break;
}
case 3: {
Timer->Interval = 100;
HomeDisplay->Visible = true;
VisitorDisplay->Visible = true;
TimeDisplay->Visible = true;
ResetGame(NULL);
break;
}
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::ShowField(bool visible)
{
Runningback->Visible = visible;
Tackler1->Visible = visible;
Tackler2->Visible = visible;
Tackler3->Visible = visible;
Tackler4->Visible = visible;
Tackler5->Visible = visible;
}
//---------------------------------------------------------------------
void __fastcall TForm1::TimerTimer(TObject *Sender)
{
int x, y, newx, newy, direction;
newy = y = random(3);
newx = x = random(10);
direction = random(2); // 0 is for x, 1 is for y
if (!running)
{
if (LastSack != NULL)
LastSack->Visible = !LastSack->Visible;
return;
}
if (field[x][y].rb == true)
return; // can't move the runningback!
if (field[x][y].player == NULL)
return; // no tacker at this spot
if (field[x][y].player->Left <= RBLEFT)
return; // already at the endzone
if (direction == 0) // we're moving horizontal
{
if (x < rbx)
newx = x +1;
else if (x > rbx)
newx = x -1;
else return;
// we're already horizontally lined up with rb
}
else if (direction == 1) // we're moving vertical
{
if (y < rby)
newy = y +1;
else if (y > rby)
newy = y -1;
else return;
// we're already vertically lined up with rb
}
if (field[newx][newy].rb == true) // got him!
{
Sacked(field[x][y].player);
return;
}
if (field[newx][newy].player == NULL) // not blocked
{
field[x][y].player->Left -= (22 * (x - newx));
field[x][y].player->Top -= (16 * (y - newy));
field[newx][newy].player = field[x][y].player;
field[x][y].player = NULL;
return;
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::Sacked(TLabel *player)
{
sndPlaySound("whistle.wav", SND_SYNC);
running = false;
LastSack = player;
if (YardsToGo <=0)
{
Down = 1;
YardsToGo = 10;
}
else
{
Down++;
if (Down > 4)
{
sndPlaySound("whistle.wav", SND_SYNC);
Down = 1; // First down for visitor
YardsToGo = 10;
Computer->Visible = true;
}
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::ResetGame(TObject *Sender)
{
YardsToGo=10;
Down=1;
FieldPosition=20;
Home=0;
Visitor=0;
Quarter = 1;
TimeLeft=15;
TimeDisplay->Caption = FloatToStrF(TimeLeft, ffGeneral, 4, 4);
HomeDisplay->Caption = itoa(Home, numbuf, 10);
VisitorDisplay->Caption = itoa(Visitor, numbuf, 10);
randomize;
ResetField();
}
//---------------------------------------------------------------------
void __fastcall TForm1::ResetField()
{
TogglePlay(false);
LastSack = NULL;
// empty the field
for (int y=0; y<3; y++)
for (int x=0; x<10; x++)
{
field[x][y].player = NULL;
field[x][y].rb = false;
}
// initial locations of players
field[0][1].player=Runningback;
field[0][1].rb=true;
rbx = 0;
rby = 1;